<template>
	<view class="login">
		<view class="content">
			<!-- 头部logo -->
			<view class="header">
				<image :src="logoImage"></image>
			</view>
			<!-- 主体表单 -->
			<view class="main">
				<wInput
					v-model="phoneData"
					type="text"
					maxlength="11"
					placeholder="用户名/电话"
					:focus="isFocus"
				></wInput>
				<wInput
					v-model="passData"
					type="password"
					maxlength="11"
					placeholder="密码"
				></wInput>
				<sunui-mverify @change="mverify" style="margin-top: 15px;border-radius: 25px"></sunui-mverify>
			</view>
			<wButton
				class="wbutton"
				text="登 录"
				:rotate="isRotate"
				@click="startLogin"
			></wButton>

			<!-- 其他登录 -->
<!--			<view class="other_login cuIcon">-->
<!--				<view class="login_icon">-->
<!--					<view class="cuIcon-weixin" @tap="login_weixin"></view>-->
<!--				</view>-->
<!--				<view class="login_icon">-->
<!--					<view class="cuIcon-weibo" @tap="login_weibo"></view>-->
<!--				</view>-->
<!--				<view class="login_icon">-->
<!--					<view class="cuIcon-github" @tap="login_github"></view>-->
<!--				</view>-->
<!--			</view>-->

			<!-- 底部信息 -->
<!--			<view class="footer">-->
<!--				<navigator url="forget" open-type="navigate">找回密码</navigator>-->
<!--				<text>|</text>-->
<!--				<navigator url="register" open-type="navigate">注册账号</navigator>-->
<!--			</view>-->
		</view>
	</view>
</template>

<script>
	let _this;
	import wInput from '../../components/watch-login/watch-input.vue' //input
	import wButton from '../../components/watch-login/watch-button.vue' //button
	import sunuiMverify from '../../components/sunui-mverify/sunui-mverify.vue';
	export default {
		data() {
			return {
				//logo图片 base64
				logoImage: 'https://tangbantian.oss-cn-beijing.aliyuncs.com/font/logo.jpg',
				phoneData:'', //用户/电话
				passData:'', //密码
				isRotate: false, //是否加载旋转
				isFocus: true ,// 是否聚焦
				moveFlag:false
			};
		},
		components:{
			wInput,
			wButton,
			sunuiMverify
		},
		mounted() {
			_this= this;
      let flag =  this.$api.customStoreageManage.getStorage("currentBrand")
      this.logoImage = flag.imgUrl
			//this.isLogin();
		},
		methods: {
			isLogin(){
				//判断缓存中是否登录过，直接登录
				// try {
				// 	const value = uni.getStorageSync('setUserData');
				// 	if (value) {
				// 		//有登录信息
				// 		console.log("已登录用户：",value);
				// 		_this.$store.dispatch("setUserData",value); //存入状态
				// 		uni.reLaunch({
				// 			url: '../../../pages/index',
				// 		});
				// 	}
				// } catch (e) {
				// 	// error
				// }
			},
		    startLogin(e){
                console.log(e)
				//登录
				if(this.isRotate){
					//判断是否加载中，避免重复点击请求
					return false;
				}
				if (this.phoneData.length == "") {
				     uni.showToast({
				        icon: 'none',
						position: 'bottom',
				        title: '用户名不能为空'
				    });
				    return;
				}
		        if (this.passData.length < 5) {
		            uni.showToast({
		                icon: 'none',
						position: 'bottom',
		                title: '密码不正确'
		            });
		            return;
		        }

				console.log("登录成功")

				this.isRotate=true
				this.login()


		    },
			login_weixin() {
				//微信登录
				uni.showToast({
					icon: 'none',
					position: 'bottom',
					title: '...'
				});
			},
			login_weibo() {
				//微博登录
				uni.showToast({
					icon: 'none',
					position: 'bottom',
					title: '...'
				});
			},
			login_github() {
				//github登录
				uni.showToast({
					icon: 'none',
					position: 'bottom',
					title: '...'
				});
			},
			login(){
				if(this.moveFlag==false){
					uni.showToast({
						title: "请输入正确的用户名或密码并托运滑块到正确的位置",
						icon: 'none',
						duration: 1000
					});
					this.isRotate=false
					return
				}
				this.$api.ajax({
					url: "/web/user/login",
					method: "post",
					headers : {
						"Content-Type": "application/json;charset=utf-8",
						"X-Requested-With":"XMLHttpRequest"
					},
					data: {
						userCode:this.phoneData,
						password:this.passData
					},
					success: (res) => {
						const { data } = res.data || {};
						const { items,zzjgId,zzjgName } = data || {};
						console.log("abc",res.data)
						console.log("zzjgid",zzjgId)
						uni.setStorageSync("jwttoken",data.token)
						uni.setStorageSync("deptId",zzjgId)
						uni.setStorageSync("deptName",zzjgName)
						this.isRotate=false
						uni.navigateTo({// url: '/pages/my/order/order'
							url:'/pages/my/shop/index'
						})
					}
				});
			},
			mverify (e) {
				this.moveFlag = e.msg
				console.log(e.msg)

			},
		}
	}
</script>

<style>
	@import url("../../components/watch-login/css/icon.css");
	@import url("./css/main.css");
</style>
